local localizedClass, englishClass = UnitClass("player");
if (englishClass == "DEATHKNIGHT") then

	local BLUTRUNE = 1
	local FROSTRUNE = 2
	local UHRUNE = 4

	facerollgcdcheck.DeathKnightBlood_1 = 45477
	facerolldb["DeathKnightBlood_1"] = 
	{
		runenwaffe = 
		{
			id=49028,
			icon=(49028),
			cd=90,
			casttime=1.5,
			ticktime=0,
			prio=100,
			resource=60,
		},
		horn = 
		{
			id=57330,
			icon=(57330),
			cd=20,
			casttime=1.5,
			ticktime=0,
			prio=5,
			resource=-10,
		},
		eb = 
		{
			id=45477,
			icon=(45477),
			cd=0,
			ticktime=3,
			debuffid = (55095),
			casttime=1.5,
			alternates={"ausbruch"},
			runen=UHRUNE, 
			prio=40,
			resource=-10,
		},
		seuchenstos= 
		{
			icon= (45462),
			id=45462,
			cd=0,
			ticktime=3,
			casttime=1.5,
			alternates={"ausbruch"},
			runen=FROSTRUNE,
			debuffid = (55078),		
			prio=30,
			resource=-10,
		},
		herzstoss= 
		{
			icon= (55050),
			id=55050,
			cd=0,
			ticktime=0,
			casttime=1.5,
			runen=BLUTRUNE,
			prio=10,
			resource=-10,
		},		
		runenstoss = 
		{
			icon = (56815),
			id=56815,
			cd=0,
			ticktime=0,
			casttime=1.5,
			prio=7,
			resource=30,
		},
		todesstoss = 
		{
			icon = (49998),
			id=49998,
			cd=0,
			ticktime=0,
			casttime=1.5,
			runen=FROSTRUNE+UHRUNE,
			prio=15,
			resource=-20,
		}, 
		mindfreeze = 
		{
			icon = 47528,
			id=47528,
			cd=10,
			casttime=1.5,
			prio=65535,
			resource=20,
			onlytointerrupt=true,
		}, 
	}

	runen={}

	function rune_filter(j, prev_spell)
		local predict_offset = 0;
		if (prev_spell) then
			predict_offset = prev_spell["casttime"]
		end
		for i=1,6 do
			runen[i]=runenberechnung(i,predict_offset)
		end
		if prev_spell ~= nil then
			runenb(prev_spell["runen"] or 0)
		end
		if ((j["runen"]==nil) or (runenb(j["runen"]))  ) then
			return true
		end
		return false
	end

	faceroll_filter.rune_filter = rune_filter;

	function runenberechnung(id,GCD)
		start, duration, runeReady = GetRuneCooldown(id)
		if ((duration+start < GetTime()+GCD))  then
			return true 
		else
			return false
		end
	end

	function runenb(runentyp)
		local b = true
		if (bit.band(runentyp, BLUTRUNE ) > 0 ) then
			b = b and runenb_orig(1)
		end
		if (bit.band(runentyp, FROSTRUNE ) > 0 ) then
			b = b and runenb_orig(2)
		end
		if (bit.band(runentyp, UHRUNE ) > 0 ) then
			b = b and runenb_orig(3)
		end
		return b
	end

	function runenb_orig(runentyp)

		for id=1,6 do
			if GetRuneType(id)==4 and runen[id] then
				runen[id]=false;
				-- print("death")
				return true
			end
		end

		for i=1,3 do
			if runentyp == i then
				if runen[i*2-1] then
					runen[i*2-1]=false
					return true
				end
				if runen[i*2] then
					runen[i*2]=false
				
					return true
				end
			end
		
		end
		return false
	end
end